﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace _00_单元测试
{

    public abstract class Operation
    {
        /// <summary>
        /// 左操作数
        /// </summary>
        public double NumberA { get; set; }
        /// <summary>
        /// 右操作数
        /// </summary>
        public double NumberB { get; set; }
        /// <summary>
        /// 计算结果
        /// </summary>
        /// <returns></returns>
        public abstract double GetResult();
    }

    //构建派生类:OperationAdd
    public class OperationAdd : Operation
    {
        public override double GetResult() 
        {
            return NumberA + NumberB;
        }
    }
    //构建派生类:OperationSub
    public class OperationSub : Operation
    {
        public override double GetResult() => NumberA - NumberB;
    }
    //构建派生类:OperationMul
    public class OperationMul : Operation
    {
        public override double GetResult() => NumberA * NumberB;
    }
    //构建派生类:OperationDiv
    public class OperationDiv : Operation
    {
        public override double GetResult() => NumberA / NumberB;
    }
    public class OperationFactory
    {
        public static Operation CreateOperationByName(string name)
        {
            Operation oper = null;
            switch (name)
            {
                case "+":
                    oper = new OperationAdd();
                    break;
                case "-":
                    oper = new OperationSub();
                    break;
                case "*":
                    oper = new OperationMul();
                    break;
                case "/":
                    oper = new OperationDiv();
                    break;
            }
            return oper;
        }
    }


    internal class Program
    {
        static void Main(string[] args)
        {
        }
    }
}
